package org.walkframework.sample.starter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.StopWatch;
import org.walkframework.boot.application.SpringPropertyHolder;
import org.walkframework.boot.ehdb.util.DynTableNameFactory;

/**
 * 示例启动器
 *
 * @author 尾生
 * @since 2024/4/8
 */
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, XADataSourceAutoConfiguration.class})
public class WalkframeworkSampleStarter extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return configureApplication(builder);
    }

    private SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
        return builder.sources(this.getClass());
    }

    public static ConfigurableApplicationContext simpleRun(Class<?> entry, String[] args) {
        return new SpringApplicationBuilder().sources(new Class[]{entry}).run(args);
    }

    public static ConfigurableApplicationContext run(Class<?> entry, String... args) {
        return SpringApplication.run(entry, args);
    }

    public static void main(String[] args) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        SpringApplication.run(WalkframeworkSampleStarter.class, args);
        stopWatch.stop();
        log.info("Application start finished with cost: {}", stopWatch.getTotalTimeSeconds());
    }

}

